package zcw.com.lib_leet_code;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 朱城委 on 2021/7/8.<br><br>
 *
 * 杨辉三角
 */
public class Topic119 {
    public static void main(String[] args) {
        Topic119 instance = new Topic119();

        System.out.println(instance.getRow(0));
        System.out.println(instance.getRow(1));
        System.out.println(instance.getRow(2));
        System.out.println(instance.getRow(3));
        System.out.println(instance.getRow(4));
        System.out.println(instance.getRow(5));
    }

    public List<Integer> getRow(int rowIndex) {
        List<Integer> result = new ArrayList<>();
        result.add(1);

        if(rowIndex == 0) {
            return result;
        }

        List<Integer> lastResult = getRow(rowIndex - 1);
        for(int i = 1; i < rowIndex; i++) {
            result.add(lastResult.get(i - 1) + lastResult.get(i));
        }

        result.add(1);
        return result;
    }
}
